package sample.viewassets.pops
{
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	
	import asf.core.Application;
	import asf.interfaces.IPopup;
	import asf.utils.Align;
	import asf.utils.FX;
	
	import sample.app.Globals;
	import sample.view.assets.CloseButton;

	public class InternalPopup extends SampleBasePop implements IPopup
	{
		private var bt:CloseButton;
		
		public function InternalPopup( )
		{
			super( );
			
			bt = new CloseButton( );
			
			visible = false;
			alpha = 0;
			
			graphics.beginFill( 0xFFCC00, 1 );
			graphics.drawRect( 0, 0, 400, 100 );
			graphics.endFill( );
			
			Align.place( bt, Align.RIGHT, { box: new Rectangle( 0, 0, width, height ) } );
			
			bt.addEventListener( MouseEvent.CLICK, click );
			
			addChild( bt );
		}
		
		private function click( evt:MouseEvent ):void
		{
			Application.getByID( Globals.APP_ID ).popups.closePopup( this.popup );
		}
		
		public function open( ):void
		{
			FX.fadeIn( this );
		}
		
		public function close( ):void
		{
			FX.fadeOut( this ).queue( popup.notifyHideEnd );
		}
		
		public function dispose( ):void
		{
			removeChild( bt );
			
			bt.removeEventListener( MouseEvent.CLICK, click );
			
			bt = null;
		}
		
	}
}